package org.ch02.job.test07;

import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * @author XCH
 * @date 2025 - 03 - 17
 */
public class MainTest {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in) ;
        System.out.println("请输入邮箱：");
        String email = sc.nextLine();
        sc.close();
        Class<?> clazz = String.class;
        Method indexOfMethod = clazz.getMethod("indexOf", String.class);
        Method substringMethod = clazz.getMethod("substring", int.class, int.class);
        int index = (int) indexOfMethod.invoke(email, "@");
        if (index == -1){
            System.out.println("邮箱格式错误");
            return;
        }
        String emailName = (String) substringMethod.invoke(email, 0, index);
        System.out.println("邮箱账号：" + emailName);

    }
}
